package com.ruoyi.project.keshi.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.keshi.domain.SysKeshi;
import com.ruoyi.project.keshi.service.ISysKeshiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 科室Controller
 *
 * @author ruoyi
 * @date 2021-09-12
 */
@RestController
@RequestMapping("/keshi/keshi")
public class SysKeshiController extends BaseController
{
    @Autowired
    private ISysKeshiService sysKeshiService;

    /**
     * 查询科室列表
     */
    @PreAuthorize("@ss.hasPermi('keshi:keshi:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysKeshi sysKeshi)
    {
        startPage();
        List<SysKeshi> list = sysKeshiService.selectSysKeshiList(sysKeshi);
        return getDataTable(list);
    }

    /**
     * 导出科室列表
     */
    @PreAuthorize("@ss.hasPermi('keshi:keshi:export')")
    @Log(title = "科室", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysKeshi sysKeshi)
    {
        List<SysKeshi> list = sysKeshiService.selectSysKeshiList(sysKeshi);
        ExcelUtil<SysKeshi> util = new ExcelUtil<SysKeshi>(SysKeshi.class);
        return util.exportExcel(list, "keshi");
    }

    /**
     * 获取科室详细信息
     */
    @PreAuthorize("@ss.hasPermi('keshi:keshi:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(sysKeshiService.selectSysKeshiById(deptId));
    }

    /**
     * 新增科室
     */
    @PreAuthorize("@ss.hasPermi('keshi:keshi:add')")
    @Log(title = "科室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysKeshi sysKeshi)
    {
        return toAjax(sysKeshiService.insertSysKeshi(sysKeshi));
    }

    /**
     * 修改科室
     */
    @PreAuthorize("@ss.hasPermi('keshi:keshi:edit')")
    @Log(title = "科室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysKeshi sysKeshi)
    {
        return toAjax(sysKeshiService.updateSysKeshi(sysKeshi));
    }

    /**
     * 删除科室
     */
    @PreAuthorize("@ss.hasPermi('keshi:keshi:remove')")
    @Log(title = "科室", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(sysKeshiService.deleteSysKeshiByIds(deptIds));
    }
}
